<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title></title>
		
		<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
		<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
	</head>
	<body>
		<div class="layui-container" style="margin: 10px 0px; ">
			<form class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">信息类型</label>
						<div class="layui-input-inline">
							<select class="layui-select" name="type">
								<option value="" title="请选择"></option>
								<option value="sms" >短信</option>
								<option value="email" >邮箱</option>
							</select>
						</div>
						
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">信息接收人</label>
						<div class="layui-input-inline">
							<input type="radio" name="accept" value="member" lay-filter="accept" title="员工" checked/>
							<input type="radio" name="accept" value="vip" lay-filter="accept" title="会员" />
						</div>	
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" style="border: 1px solid #708090;">
						<div>
							<input type="radio" name="acceptType" lay-filter="member" value="all" title="所有员工" checked/>
							<input type="radio" name="acceptType" lay-filter="member" value="some" title="指定员工"/>
							<hr id="hr" style="display: none;"/>
							<div id="acceptUser" style="display: none;">

								<input type="checkbox" name="acceptUser" value="123" title="test1" />

							</div>
						</div>
					</div>	
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">信息标题</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input" name="title" />
					</div>	
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">信息内容</label>
					<div class="layui-input-block">
						<textarea class="layui-textarea" name="content"></textarea>
					</div>	
				</div>
				<div class="layui-form-item" style="display: none;">
					<div class="layui-input-block">
						<a class="layui-btn" id="submitBtn" lay-submit="" lay-filter="submitBtn">提交</a>
					</div>	
				</div>
			</form>
		</div>
		<script>
			
			var $,form;
			// layui.config({
			// 	base:'../js/'
			// })
			layui.use(['form','jquery','layer'],function(){
				 form = layui.form;
				$ = layui.jquery;
				var layer=layui.layer;

				getAllMember();
				form.on('submit(submitBtn)',function (data){
				   var formData=data.field;
				   $.ajax({
					   type: 'post',
					   url: '/system/smc/add',
					   data:formData,
					   dataType: 'json',
					   success:function (result){
					   	layer.alert(result.msg);
                          if(result.is){
							  let index = parent.layer.getFrameIndex(window.name);
							  parent.layer.close(index);//关闭父页面窗口
						  }
					   }
				   })


				})

				
				
				form.on('radio(accept)',function(data){
					var value = data.value;
					var all = "",some="";
					if(value=='member'){
						all="所有员工",some="指定员工";
						getAllMember();

					}else{
						all="所有会员",some="指定会员";
						getAllVip();
					}
					$('input[value="all"]').attr('title',all).next().find('div').html(all);
					$('input[value="some"]').attr('title',some).next().find('div').html(some);
				})
				form.on('radio(member)',function(data){
					var value = data.value;
					var all = "",some="";
					if(value=='all'){
						$("#hr").hide();
						$("#acceptUser").hide();
					}else{
						$("#hr").show();
						$("#acceptUser").show();
					}
					
				})
			
				//菜单下拉树
			// 	treeSelect.render({
			// 		elem:'#pid',
			// 		placeholder:"选择子菜单的父菜单",
			// 		search:true,
			// 		data:'../data/treeSelect.json',
			// 		type:'get',
			// 		success:function(data){
			// 			$('.layui-treeSelect').css('width','375px');
			// 			$('.layui-treeSelect').css('display','none');
			// 		},
			// 		click:function(data){
			// 			var current = data.current;
			// 			var pid = current.id;
			// 			$('#parentId').val(pid);
			// 		}
			// 	})
			//
			//
			});
			function  getAllMember(){
				$.ajax({
					type:'post',
					url:'/system/mc/find',
					data:{
						limit:100
					},
					dataType:'json',
					success:function (result){
						$('#acceptUser').empty();//清空
						$.each(result.data,function (i,m){
							var ele='<input type="checkbox" name="acceptUsers[]" value="'+m.loginName+'" title="'+m.userName+'" />';
							$('#acceptUser').append(ele);
						})
						form.render();//表单控件刷新
					}
				})
			}

			function  getAllVip(){
				//TODO 查询所有会员
			}
			
			function btnSubmit(){
				$('#submitBtn').click();
			}
		</script>
	</body>
</html>
